#parse argument

architecture=$1
matrix_decompressed_file=$2
matrix_comp_file=$3
output_dir=$4
lorem_ipsum_file=$5

permutation_str=""

# make signature

str="
xrnlib-cli \
    --encoding-conf -compiled-param -no-password \
    --permutation-conf -arch $architecture $permutation_str \
    --make-monomial-key -monomial-key $output_dir/monomial_key_file.xf 
"
echo ""; echo $str; echo ""
eval $str

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --encoding-conf -compiled-param -no-password \
    --arithmetic-conf -monomial-key $output_dir/monomial_key_file.xf \
    --sequence-conf -xmatrix $matrix_decompressed_file \
    --permutation-conf -arch $architecture \
    --make-signature-symmetric -plain-text $lorem_ipsum_file -symmetric-signature $output_dir/signature_file.xf
"
echo ""; echo $str; echo ""
eval $str

# make commitment

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --encoding-conf -compiled-param -no-password \
    --arithmetic-conf -sym-signature $output_dir/signature_file.xf \
    --sequence-conf -xmatrix $matrix_decompressed_file \
    --permutation-conf -arch $architecture \
    --make-commitment-sym-signature -monomial-commitment $output_dir/monomial_commitment_file.xf
-binomial-commitment $output_dir/binomial_commitment_file.xf -plain-text $lorem_ipsum_file
"
echo ""; echo $str; echo ""
eval $str

# generate response

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --permutation-conf -arch 128 \
    --logging-conf -lib-error-log $output_dir/binomial_commitment.err -lib-info-log $output_dir/binomial_commitment.info \
    --print-header -xrn-file $output_dir/binomial_commitment_file.xf ; \
if grep -q XRN-ERR \"$output_dir/binomial_commitment.err\" ; then \
    rm $output_dir/binomial_commitment.err ; \
    rm $output_dir/binomial_commitment.info ; \
    xrnlib-cli \
        --decoding-conf -compiled-param -no-password \
        --permutation-conf -arch 256 \
        --logging-conf -lib-info-log $output_dir/binomial_commitment.info \
        --print-header -xrn-file $output_dir/binomial_commitment_file.xf ; \
fi
"
echo ""; echo $str; echo ""
eval $str

bob_architecture=$(cat $output_dir/binomial_commitment.info | grep nbits | sed 's/^.*:.// ; s/.$//')
bob_permutation_used=$(cat $output_dir/binomial_commitment.info | grep permutation_used | sed 's/^.*:.//')

bob_permutation_str=""

str="
xrnlib-cli \
    --encoding-conf -compiled-param -no-password \
    --permutation-conf -arch $bob_architecture $bob_permutation_str \
    --make-response -monomial-response $output_dir/monomial_response_file.xf
"
echo ""; echo $str; echo ""
eval $str

# generate proof

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --encoding-conf -compiled-param -no-password \
    --arithmetic-conf -monomial-key $output_dir/monomial_key_file.xf -sym-signature $output_dir/signature_file.xf -monomial-commitment $output_dir/monomial_commitment_file.xf -monomial-response $output_dir/monomial_response_file.xf \
    --sequence-conf -xmatrix $matrix_decompressed_file \
    --permutation-conf -arch $architecture \
    --make-monomial-proof-sym-signature -monomial-proof $output_dir/monomial_proof_file.xf -plain-text $lorem_ipsum_file
"
echo ""; echo $str; echo ""
eval $str

# check proof

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --arithmetic-conf -sym-signature $output_dir/signature_file.xf -binomial-commitment $output_dir/binomial_commitment_file.xf -monomial-response $output_dir/monomial_response_file.xf -monomial-proof $output_dir/monomial_proof_file.xf -no-const-exec-time \
    --sequence-conf -xmatrix $matrix_decompressed_file \
    --permutation-conf -arch $bob_architecture \
    --logging-conf -lib-info-log $output_dir/lib_info_log_file.xf \
    --check-monomial-proof-sym-signature -plain-text $lorem_ipsum_file
"
echo ""; echo $str; echo ""
eval $str

str=" 
if ! [ -s $output_dir/lib_info_log_file.xf ]; then echo FAIL ; exit ; fi ; \
if cat $output_dir/lib_info_log_file.xf | grep -q 'PASS' ; then echo 'PASS' ; else echo 'FAIL' ; fi
"
echo ""; echo $str; echo ""
eval $str


